package com.global.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;


/**
 * Generic DAO (Data Access Object) with common methods to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) DAO's for your domain objects.
 *
 * @author <a href="mailto:bwnoll@gmail.com">Bryan Noll</a>
 * @author zly601436
 * 
 * @param <T> a type variable
 * @param <PK> the primary key for that type
 */
public interface GenericDao <T, PK extends Serializable> {

    /**
     * Generic method used to get all objects of a particular type. This
     * is the same as lookup up all rows in a table.
     * <br/>用于检索出某个实体（包含所有属性）对应的所有对象，相当于在table中检索所有记录
     * @return List of populated objects
     */
    List<T> getAll();

    /**
     * Gets all records without duplicates.
     * <p>Note that if you use this method, it is imperative that your model
     * classes correctly implement the hashcode/equals methods</p>
     * <br/>用于检索出某个实体（包含所有属性）中对应的所有不同对象
     * <br/>注意：在使用本方法之前，需要事先实现实体类中的hashcode/equals方法
     * <br/>注意：返回的记录可能是无序的，可以在具体实现时，再增加排序规则
     * @return List of populated objects
     */
    List<T> getAllDistinct();

    /**
     * Generic method to get an object based on class and identifier. An
     * ObjectRetrievalFailureException Runtime Exception is thrown if
     * nothing is found.
     * <br/>通过主键ID检索出某个实体对象，如果没有找到，则发出异常
     *
     * @param id the identifier (primary key) of the object to get
     * @return a populated object
     * @see org.springframework.orm.ObjectRetrievalFailureException
     */
    T get(PK id);

    /**
     * Checks for existence of an object of type T using the id arg.
     * <br/>通过主键ID来验证某个实体对象是否存在
     * @param id the id of the entity     * 
     * @return - true if it exists, false if it doesn't
     */
    boolean exists(PK id);

    /** 
     * Generic method to save an object - handles both update and insert.
     * <br/>用于保存对象的通用方法，即包含update与insert
     * @param object the object to save
     * @return the persisted object
     */
    T save(T object);

    /**
     * Generic method to delete an object based on class and id
     * <br/>通过主键ID删除对象的通用方法
     * @param id the identifier (primary key) of the object to remove
     */
    void remove(PK id);

    /**
     * 通过事先定义好的查询名检索出一组记录
     * @param queryName query name of the named query
     * @param queryParams a map of the query names and the values
     * @return a list of the records found
     */
    List<T> findByNamedQuery(String queryName, Map<String, Object> queryParams);
}